package com.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.bean.AnswerQuesBean;
import com.xiaochun.hxhj.R;

import java.util.List;


public class NineTableNumAdapter extends BaseAdapter {


    private Context context;
    private LayoutInflater mInflater;
    List<AnswerQuesBean.DataBean.AnswerBean> mData;
    public int checkedPosition = 0;
    public boolean isshow = true;
    public boolean isCheck = false;
    public String checkposs = "";
    public boolean istrue = true;
    public int width = 90;

    public NineTableNumAdapter(Context context){
        this.mInflater = LayoutInflater.from(context);
    }

    public NineTableNumAdapter(Context context, List<AnswerQuesBean.DataBean.AnswerBean> mData){
        this.context=context;
        this.mInflater = LayoutInflater.from(context);
        this.mData=mData;


    }
    public void setData(List<AnswerQuesBean.DataBean.AnswerBean> mData,int width){
        this.mData=mData;
        this.width=width;
        checkedPosition = 0;
        isshow = true;
        isCheck = false;
        checkposs = "";
        istrue = true;
        notifyDataSetChanged();
    }
    public void setGone(){
        isshow = false;
        notifyDataSetChanged();
    }
    public void setCheckedItem(int position,String checkposs,boolean istrue){
        this.checkedPosition=position;
        this.checkposs=checkposs;
        this.istrue=istrue;
        isshow = false;
        isCheck = true;
        notifyDataSetChanged();
    }
    @Override
    public int getCount() {
        return mData.size();
    }

    @Override
    public Object getItem(int arg0) {
        return null;
    }

    @Override
    public long getItemId(int arg0) {
        return 0;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            holder=new ViewHolder();
            convertView = mInflater.inflate(R.layout.item_nine_table, null);
            holder.img_nine_table = (ImageView) convertView.findViewById(R.id.img_nine_table);
            convertView.setTag(holder);
        }else {
            holder = (ViewHolder)convertView.getTag();
        }
        LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) holder.img_nine_table.getLayoutParams();
        layoutParams.height = width;
        layoutParams.width = width;
        holder.img_nine_table.setLayoutParams(layoutParams);

        if (isshow){
            holder.img_nine_table.setVisibility(View.VISIBLE);
        }else{
            holder.img_nine_table.setImageResource(R.color.colortrans);
            holder.img_nine_table.setVisibility(View.INVISIBLE);
        }
        if (isCheck){
            String[] split = checkposs.split("-");
            if (istrue){
                for (int i = 0;i<split.length;i++){
                    if (Integer.parseInt(split[i]) == position){
                        holder.img_nine_table.setVisibility(View.VISIBLE);
                        //正确
                        //课程类型:0=九宫格心形,1=九宫格星星,2=九宫格笑脸,3=九宫格五角星,4=听记,5=数字听力,6=数字位置,7=点的记忆,8=图形记忆
                        String opt = mData.get(position).getOpt_answer();
                        if ("0".equals(opt)){
                            holder.img_nine_table.setImageResource(R.color.colortrans);
                        }else if ("1".equals(opt)){
                            holder.img_nine_table.setImageResource(R.mipmap.icon_num_one);
                        }else if ("2".equals(opt)){
                            holder.img_nine_table.setImageResource(R.mipmap.icon_num_two);
                        }else if ("3".equals(opt)){
                            holder.img_nine_table.setImageResource(R.mipmap.icon_num_three);
                        }else if ("4".equals(opt)){
                            holder.img_nine_table.setImageResource(R.mipmap.icon_num_fore);
                        }else if ("5".equals(opt)){
                            holder.img_nine_table.setImageResource(R.mipmap.icon_num_five);
                        }else if ("6".equals(opt)){
                            holder.img_nine_table.setImageResource(R.mipmap.icon_num_six);
                        }else if ("7".equals(opt)){
                            holder.img_nine_table.setImageResource(R.mipmap.icon_num_seven);
                        }else if ("8".equals(opt)){
                            holder.img_nine_table.setImageResource(R.mipmap.icon_num_eight);
                        }else if ("9".equals(opt)){
                            holder.img_nine_table.setImageResource(R.mipmap.icon_num_nine);
                        }else if ("10".equals(opt)){
                            holder.img_nine_table.setImageResource(R.mipmap.icon_num_ten);
                        }else if ("11".equals(opt)){
                            holder.img_nine_table.setImageResource(R.mipmap.icon_num_eleven);
                        }else if ("12".equals(opt)){
                            holder.img_nine_table.setImageResource(R.mipmap.icon_num_twelve);
                        }else if ("13".equals(opt)){
                            holder.img_nine_table.setImageResource(R.mipmap.icon_num_thirteen);
                        }else if ("14".equals(opt)){
                            holder.img_nine_table.setImageResource(R.mipmap.icon_num_fourteen);
                        }else if ("15".equals(opt)){
                            holder.img_nine_table.setImageResource(R.mipmap.icon_num_fifteen);
                        }else if ("16".equals(opt)){
                            holder.img_nine_table.setImageResource(R.mipmap.icon_num_sixteen);
                        }

                    }
                }

            }else{
                //全部显示出来
                holder.img_nine_table.setVisibility(View.VISIBLE);
                String opt = mData.get(position).getOpt_answer();
                if ("0".equals(opt)){
                    //课程类型:0=九宫格心形,1=九宫格星星,2=九宫格笑脸,3=九宫格五角星,4=听记,5=数字听力,6=数字位置,7=点的记忆,8=图形记忆
                    holder.img_nine_table.setImageResource(R.color.colortrans);
                }else if ("1".equals(opt)){
                    holder.img_nine_table.setImageResource(R.mipmap.icon_num_one);
                }else if ("2".equals(opt)){
                    holder.img_nine_table.setImageResource(R.mipmap.icon_num_two);
                }else if ("3".equals(opt)){
                    holder.img_nine_table.setImageResource(R.mipmap.icon_num_three);
                }else if ("4".equals(opt)){
                    holder.img_nine_table.setImageResource(R.mipmap.icon_num_fore);
                }else if ("5".equals(opt)){
                    holder.img_nine_table.setImageResource(R.mipmap.icon_num_five);
                }else if ("6".equals(opt)){
                    holder.img_nine_table.setImageResource(R.mipmap.icon_num_six);
                }else if ("7".equals(opt)){
                    holder.img_nine_table.setImageResource(R.mipmap.icon_num_seven);
                }else if ("8".equals(opt)){
                    holder.img_nine_table.setImageResource(R.mipmap.icon_num_eight);
                }else if ("9".equals(opt)){
                    holder.img_nine_table.setImageResource(R.mipmap.icon_num_nine);
                }else if ("10".equals(opt)){
                    holder.img_nine_table.setImageResource(R.mipmap.icon_num_ten);
                }else if ("11".equals(opt)){
                    holder.img_nine_table.setImageResource(R.mipmap.icon_num_eleven);
                }else if ("12".equals(opt)){
                    holder.img_nine_table.setImageResource(R.mipmap.icon_num_twelve);
                }else if ("13".equals(opt)){
                    holder.img_nine_table.setImageResource(R.mipmap.icon_num_thirteen);
                }else if ("14".equals(opt)){
                    holder.img_nine_table.setImageResource(R.mipmap.icon_num_fourteen);
                }else if ("15".equals(opt)){
                    holder.img_nine_table.setImageResource(R.mipmap.icon_num_fifteen);
                }else if ("16".equals(opt)){
                    holder.img_nine_table.setImageResource(R.mipmap.icon_num_sixteen);
                }
            }

        }else{
            String opt = mData.get(position).getOpt_answer();
            if ("0".equals(opt)){
                //课程类型:0=九宫格心形,1=九宫格星星,2=九宫格笑脸,3=九宫格五角星,4=听记,5=数字听力,6=数字位置,7=点的记忆,8=图形记忆
                holder.img_nine_table.setImageResource(R.color.colortrans);
            }else if ("1".equals(opt)){
                holder.img_nine_table.setImageResource(R.mipmap.icon_num_one);
            }else if ("2".equals(opt)){
                holder.img_nine_table.setImageResource(R.mipmap.icon_num_two);
            }else if ("3".equals(opt)){
                holder.img_nine_table.setImageResource(R.mipmap.icon_num_three);
            }else if ("4".equals(opt)){
                holder.img_nine_table.setImageResource(R.mipmap.icon_num_fore);
            }else if ("5".equals(opt)){
                holder.img_nine_table.setImageResource(R.mipmap.icon_num_five);
            }else if ("6".equals(opt)){
                holder.img_nine_table.setImageResource(R.mipmap.icon_num_six);
            }else if ("7".equals(opt)){
                holder.img_nine_table.setImageResource(R.mipmap.icon_num_seven);
            }else if ("8".equals(opt)){
                holder.img_nine_table.setImageResource(R.mipmap.icon_num_eight);
            }else if ("9".equals(opt)){
                holder.img_nine_table.setImageResource(R.mipmap.icon_num_nine);
            }else if ("10".equals(opt)){
                holder.img_nine_table.setImageResource(R.mipmap.icon_num_ten);
            }else if ("11".equals(opt)){
                holder.img_nine_table.setImageResource(R.mipmap.icon_num_eleven);
            }else if ("12".equals(opt)){
                holder.img_nine_table.setImageResource(R.mipmap.icon_num_twelve);
            }else if ("13".equals(opt)){
                holder.img_nine_table.setImageResource(R.mipmap.icon_num_thirteen);
            }else if ("14".equals(opt)){
                holder.img_nine_table.setImageResource(R.mipmap.icon_num_fourteen);
            }else if ("15".equals(opt)){
                holder.img_nine_table.setImageResource(R.mipmap.icon_num_fifteen);
            }else if ("16".equals(opt)){
                holder.img_nine_table.setImageResource(R.mipmap.icon_num_sixteen);
            }
        }
        return convertView;
    }
    public static class ViewHolder{
        ImageView img_nine_table ;
    }


}